package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.CommodityType;
import com.xuetang9.t9.hotel.beans.Reservation;
import com.xuetang9.t9.hotel.mapper.condition.impl.CommodityTypeCondition;
import com.xuetang9.t9.hotel.mapper.condition.impl.ReservationCondition;
import com.xuetang9.t9.hotel.services.ICommodityTypeService;
import com.xuetang9.t9.hotel.utils.HttpCodeEnum;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 商品类型controller
 */
@Controller
@RequestMapping("/commtype")
@ResponseBody
public class CommodityTypeController {
    @Autowired
    private ICommodityTypeService commodityTypeService;


    /**
     * 列表查询
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/show",method = RequestMethod.POST)
    private PageBean show(CommodityTypeCondition condition){
        return commodityTypeService.queryByAll(condition);
    }


    /**
     * 新添加预订订单
     * @param reservation
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    private ResponseResult save(@RequestBody CommodityType commodityType){
        if(commodityType == null){
            return null;
        }
        commodityTypeService.save(commodityType);
        return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
    }


    /**
     * 删除订单
     * @param id
     * @return
     */
    @RequestMapping("/remove/{id}")
    private ResponseResult remove(@PathVariable("id") Integer id){
        if(id == null){
            return null;
        }
        if(commodityTypeService.remove(id)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return  ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
    }


    /**
     * 更新预订订单
     * @param reservation
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    private ResponseResult update(@RequestBody CommodityType commodityType){
        if (null == commodityType){
            return null;
        }
        if(commodityTypeService.update(commodityType)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return  ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
    }
}
